package com.yanqu.road.dataHelper.utils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class TextData {

    private static void makeDir(){
        String path = System.getProperty("user.dir") + File.separator + "outText";
        File f = new File(path);
        if(!f.exists()){
            f.mkdirs(); //创建目录
        }
    }

    public static void outTextData(String fileName,List<String> outData) throws IOException {
        try{
            makeDir();
            String dirPath = System.getProperty("user.dir") + File.separator;
            System.err.println(dirPath + "outText" + File.separator + fileName + "_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()).toString() +".txt");
            File file = new File(dirPath + "outText" + File.separator + fileName + "_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()).toString() +".txt");
            if(!file.exists()){
                file.createNewFile();
            }
            //使用true，即进行append file
            FileWriter fileWriter = new FileWriter(file.getPath(),true);
            for(String lineContent : outData){
                fileWriter.write(lineContent + "\n");
            }
            fileWriter.close();
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}
